<?php
/**
 * CompleXml Framework
 *
 * @category   CompleXml
 * @package    CompleXml_Object
 * @copyright  Copyright (c) 2008 Andrey Kucherenko
 * @license    New BSD License
 * @version    0.1
 */
require_once 'CompleXml/Object/Abstract.php';
require_once 'CompleXml/Dataset/Request.php';
class CompleXml_Object_Controller extends CompleXml_Object_Abstract
{
	/**
	 * CompleXml_Dataset_Request object
	 * @var CompleXml_Dataset_Request
	 */
	public $Request;

	private $_controllers_path = null;

	public function __construct ()
	{
		$this->Request = new CompleXml_Dataset_Request();
	}

	public function setControllerPath($path)
	{
		$this->_controllers_path = $path;
	}

	protected function start($page, $actions=null, $template=null,  $handlers=null, $locale=null)
	{

		if (!file_exists($this->_controllers_path.DIRECTORY_SEPARATOR.$page.'.php')){
			require_once 'CompleXml/Object/Controller/Exception.php';
			throw new CompleXml_Object_Controller_Exception('Controller "'.$this->_controllers_path.DIRECTORY_SEPARATOR.$page.'.php" not exists');
		}
		
		CompleXml_Config::set('complexml_actions', $actions);
		CompleXml_Config::set('complexml_template', $template);
		CompleXml_Config::set('complexml_handlers', $handlers);
		CompleXml_Config::set('complexml_locale', $locale);
		
		require_once($this->_controllers_path.DIRECTORY_SEPARATOR.$page.'.php');
		CompleXml_Core::start(new $page);
	}
}